package com.china.osourcechina;

import android.os.Message;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.widget.ListView;

import com.china.adapter.Friends_Adapter;
import com.china.base.BaseActivity;
import com.china.utils.HttpUtils;
import com.china.vo.Active;
import com.thoughtworks.xstream.XStream;

import org.xmlpull.v1.XmlPullParser;

import java.util.ArrayList;

/**
 * Created by jinyaoguang on 2016/5/10.
 */
public class Friends_Activity extends BaseActivity {

    SwipeRefreshLayout sr;
    ListView lv_friends;
    int  pager=0;
    ArrayList<Active> list;

    XmlPullParser parser;

    android.os.Handler h=new android.os.Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            lv_friends.setAdapter(new Friends_Adapter(list,Friends_Activity.this));
        }
    };
    @Override
    protected int loadWindowLayout() {
        return R.layout.activity_friends;
    }

    @Override
    protected void initTitleBar() {

    }

    @Override
    protected void initViews() {
        sr = (SwipeRefreshLayout) findViewById(R.id.sr);
        lv_friends = (ListView) findViewById(R.id.lv_friends);
        initData();
    }

    private void initData() {

        String str= HttpUtils.get("http://www.oschina.net/action/api/active_list?uid=2757560&catalog=1&pageIndex=0&pageSize=20");
        Log.i("ssss",str.toString());
        //实例化Xstream
        XStream x = new XStream();
        //解析对象
        x.processAnnotations(My_Oschina.class);
        //实例化对象
        My_Oschina os = new My_Oschina();
        //得到解析数据
        os = (My_Oschina) x.fromXML(str);
        //清除集合
        list.clear();
        //得到集合
        list = os.getActivies().getActive();

        Log.i("aa",list.toString());
        h.sendEmptyMessage(0);
    }
}
